
#include <BMaterial>
#include "member_BMaterial.h"

using namespace BWE;

#define member					(*(member_BMaterial*)_ptr)
#define member_allocate()		_ptr = new member_BMaterial(this)
#define member_release()		delete (member_BMaterial*)_ptr

BMaterial::BMaterial(const BColor& color)
{
	member_allocate();
	setAmbient(color % 30);
	setDiffuse(color % 80);
	setSpecular(color % 50);
	setShininess(20);
}
BMaterial::~BMaterial()
{
	member_release();
}

void BMaterial::setAmbient(const BColor& ambient)
{
	if (member.ambient != ambient)
	{
		member.ambient = ambient;
		member.ambientColor.r() = ambient.r() / 255.0f;
		member.ambientColor.g() = ambient.g() / 255.0f;
		member.ambientColor.b() = ambient.b() / 255.0f;
		member.ambientColor.a() = ambient.a() / 255.0f;
	}
}
void BMaterial::setAmbient(BByte r, BByte g, BByte b, BByte a)
{
	setAmbient(BColor(r, g, b, a));
}
const BColor& BMaterial::ambient() const
{
	return member.ambient;
}

void BMaterial::setDiffuse(const BColor& diffuse)
{
	if (member.diffuse != diffuse)
	{
		member.diffuse = diffuse;
		member.diffuseColor.r() = diffuse.r() / 255.0f;
		member.diffuseColor.g() = diffuse.g() / 255.0f;
		member.diffuseColor.b() = diffuse.b() / 255.0f;
		member.diffuseColor.a() = diffuse.a() / 255.0f;
	}
}
void BMaterial::setDiffuse(BByte r, BByte g, BByte b, BByte a)
{
	setDiffuse(BColor(r, g, b, a));
}
const BColor& BMaterial::diffuse() const
{
	return member.diffuse;
}

void BMaterial::setSpecular(const BColor& specular)
{
	if (member.specular != specular)
	{
		member.specular = specular;
		member.specularColor.r() = specular.r() / 255.0f;
		member.specularColor.g() = specular.g() / 255.0f;
		member.specularColor.b() = specular.b() / 255.0f;
		member.specularColor.a() = specular.a() / 255.0f;
	}
}
void BMaterial::setSpecular(BByte r, BByte g, BByte b, BByte a)
{
	setSpecular(BColor(r, g, b, a));
}
const BColor& BMaterial::specular() const
{
	return member.specular;
}

void BMaterial::setEmission(const BColor& emission)
{
	if (member.emission != emission)
	{
		member.emission = emission;
		member.emissionColor.r() = emission.r() / 255.0f;
		member.emissionColor.g() = emission.g() / 255.0f;
		member.emissionColor.b() = emission.b() / 255.0f;
		member.emissionColor.a() = emission.a() / 255.0f;
	}
}
void BMaterial::setEmission(BByte r, BByte g, BByte b, BByte a)
{
	setEmission(BColor(r, g, b, a));
}
const BColor& BMaterial::emission() const
{
	return member.emission;
}

void BMaterial::setShininess(float shininess)
{
	member.shininess = shininess;
}

float BMaterial::shininess() const
{
	return member.shininess;
}

